package org.acghub.config.type;

import org.acghub.config.Reward;
import org.acghub.config.Type;
import org.acghub.config.TypeInstanceException;

/**
 * @Desc
 * @Author miyuki4j
 * @Date 2025/7/24/星期四 14:38
 * @Version 1.0
 */
public class RewardType implements Type.SimpleType<Reward> {

    @Override
    public String name() {
        return "reward";
    }

    @Override
    public String javaInterface() {
        return "org.acghub.config.Reward";
    }

    @Override
    public String defaultValue() {
        return "null";
    }

    @Override
    public Reward instance(String value, String delimiters) throws TypeInstanceException {
        try {
            String delimiter = String.valueOf(delimiters.charAt(0));
            String[] rewardStrArr = value.split(delimiter);
            int type = Integer.parseInt(rewardStrArr[0]);
            int id = Integer.parseInt(rewardStrArr[1]);
            int amount = Integer.parseInt(rewardStrArr[2]);
            return new Reward(type, id, amount);
        } catch (Exception e) {
            throw new TypeInstanceException("parse reward value:" + value, e);
        }
    }
}
